//
//  InfoOneDir.m
//  OA
//
//  Created by apple on 15-11-19.
//  Copyright (c) 2015年 net. All rights reserved.
//

#import "InfoOneDir.h"
#import "AppDelegate.h"
#import "Constants.h"
#import "InfoTwoDirViewController.h"
@implementation InfoOneDir

NSMutableArray * oneDirs;
AppDelegate * appDelegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"一级目录";
    self.table.dataSource= self;
    self.table.delegate = self;
    oneDirs = [[NSMutableArray alloc] init];
    appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate.manager
     GET:url2
     parameters:nil
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
         //oneDirs = responseObject;
         [oneDirs addObjectsFromArray:responseObject];
         //NSLog(@"%d",[oneDirs count]);
         [self.table reloadData];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"获取服务器响应出错！");
     }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return oneDirs.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"oneDirCell" forIndexPath:indexPath];
    cell.layer.cornerRadius=12;
    cell.layer.masksToBounds=YES;
    UILabel * label = (UILabel*)[cell viewWithTag:1];
    label.text = [[oneDirs objectAtIndex:indexPath.row] objectForKey:@"dirName"];
    return cell;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UITableViewCell * cell = (UITableViewCell*)sender;
    NSIndexPath * indexPath = [self.table indexPathForCell:cell];
    // [[oneDirs objectAtIndex:indexPath.row] objectForKey:@"id"];
    InfoTwoDirViewController * infoTwoViewController = (InfoTwoDirViewController*)segue.destinationViewController;
    //NSLog(@"%@",[[oneDirs objectAtIndex:indexPath.row] objectForKey:@"id"]);
    infoTwoViewController.infoOneDirId = [[oneDirs objectAtIndex:indexPath.row] objectForKey:@"id"];
}
@end
